class AnswerResultItemModel {
    constructor(param) {
        const {
            id,
            articleExercisesId,
            questionTypeId,
            articleId,
            num,
            userAnswer,
            userAnswerDetail,
            isCorrect,
            score,
            updateUserId,
            updateUserName
        } = param || {}
        this.id = id;
        this.articleExercisesId = articleExercisesId;
        this.questionTypeId = questionTypeId;
        this.articleId = articleId;
        this.num = num;
        this.userAnswer = userAnswer;
        this.userAnswerDetail = userAnswerDetail;
        this.isCorrect = isCorrect;
        this.score = score;
        this.level = getLevel.call(this, score);
        this.updateUserId = updateUserId;
        this.updateUserName = updateUserName;
    }
}

export default class AnswerResultModel {
    constructor(param) {
        const {
            total, // 总题数
            already, // 已完成题数
            comprehensiveScore, // 总得分
            list
        } = param || {}
        this.total = total;
        this.already = already;
        this.isFinish = total == already;
        this.comprehensiveScore = comprehensiveScore;
        this.level = getLevel.call(this, comprehensiveScore);
        this.list = list ? list.map(item => {
            return new AnswerResultItemModel(item)
        }) : []
    }
}

function getLevel(score) {
    if (!score) return 0;
    if (score < 50) {
        return 1;
    } else if (score < 80) {
        return 2;
    } else {
        return 3;
    }
}